package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 当前登录用户相关操作
 */
public class UserSessionUtils {

    /**
     * 得到当前登录的用户
     */
    public static UserInfo getUser(HttpServletRequest request){

        HttpSession session = request.getSession(false);
        if (session != null &&
                session.getAttribute(AppVariable.USER_SESSION_KEY) != null){
            // 说明用户已登录
            return (UserInfo) session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return null;
    }
}
